import { createSlice } from '@reduxjs/toolkit';
import ums from '../../apis/ums';
import { message } from 'antd';
const accountSlice = createSlice({
    name: 'account',
    initialState: {
        data: [],
        total: 0,
        loading: false
    },
    reducers: {
        setData(state, action) {
            state.data = action.payload.data
            state.total = action.payload.total;
        },
        setLoading(state, action) {
            state.loading = action.payload;

        },
    }
})

export const getData = (params) => async(dispatch) => {
    dispatch(accountSlice.actions.setLoading(true))
    await ums.getAccountList(params).then(res => {
        dispatch(accountSlice.actions.setData({ data: res.data.data, total: res.data.totalCount }))
        dispatch(accountSlice.actions.setLoading(false))
    })
}
export const del = (_id) => async(dispatch) => {
    await ums.delAccount({ id: _id._id }).then(res => {
        if (res.code == 1) {
            message.success("删除成功")
        }
    })
    dispatch(getData())
}
export default accountSlice.reducer